import cv2 as cv
import numpy as np


def sobel_demo(image):
    # grad_x = cv.Sobel(image,cv.CV_32F,1,0)
    # grad_y = cv.Sobel(image,cv.CV_32F,0,1)
    grad_x = cv.Scharr(image, cv.CV_32F, 1, 0)#enhance
    grad_y = cv.Scharr(image, cv.CV_32F, 0, 1)
    gradx = cv.convertScaleAbs(grad_x)
    grady = cv.convertScaleAbs(grad_y)
    cv.imshow('grad-x',gradx)
    cv.imshow('grad-y',grady)
    added = cv.addWeighted(gradx,0.5,grady,0.5,0)
    cv.imshow('added',added)


def laplacian_demo(image):
    # dst = cv.Laplacian(image,cv.CV_32F)
    # lpls = cv.convertScaleAbs(dst)
    #kernel -4 == default laplacian
    kernel = np.array([[0,1,0],[1,-4,1],[0,1,0]])
    dst = cv.filter2D(image,cv.CV_32F,kernel)
    lpls = cv.convertScaleAbs(dst)

    cv.imshow('lpls',lpls)


src = cv.imread('lena.jpg', 1)
cv.namedWindow('demo',cv.WINDOW_AUTOSIZE)
cv.imshow('demo', src)
laplacian_demo(src)
cv.waitKey(0)
cv.destroyWindow('demo')